<template>
<view>
<!--<import src="../../template/login-model.wxml"></import>-->
<block data-type="template" data-is="tempLogin" data-attr="loginModelHidden:loginModelHidden">
    <view class="loginModel" :hidden="loginModelHidden">
        <image class="loginImg" src="/static/img/login.png"></image>
        <view class="loginText">我们需要获得您的授权，以继续操作</view>
        <button @getuserinfo="updateUserInfo" class="loginBtn" openType="getUserInfo">
            <image class="loginBtnimg" src="/static/img/weixin.png"></image>微信授权登录</button>
    </view>
    <view class="loginBg" :hidden="loginModelHidden"></view>
</block>
<view class="user">
	<image src="/static/remao_shop/img/bj.png" class="bjimg"></image>
	<view class="user-url" style="background:#999999">
		<image :src="userHeadImg" class="userAvatar"></image>
		<!-- <open-data type="userAvatarUrl"></open-data> -->
		<!-- <image class="userAvatar" src="{{getList.avatarUrl}}"></image> -->
	</view>
	<view class="user-name">
		<!-- <open-data type="userNickName" bindtap='totemp'></open-data> -->
		<view class="userName" v-if="userName">{{userName}}</view>
		<view class="userName" v-else="userName"><button @getuserinfo="getUser" open-type="getUserInfo">请登录</button></view>
	</view>
</view>
<!-- <button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button> -->
<view class="order-warp">
	<view class="order" @tap="toOrderOne" style="padding-right:30rpx;">
		<text>全部订单</text>
		<image class="order-top" src="/static/remao_shop/img/arrow_icon.png"></image>
	</view>
	<view class="list-warp pay-warp">
		<view @tap="toOrderTwo" class="pay list">
			<view>
				<image src="/static/remao_shop/img/daizhifu_icon.png"></image>
				<text>待付款</text>
			</view>
		</view>
		<view @tap="toOrderThree" class="pay list">
			<view>
				<image src="/static/remao_shop/img/daifahuo_icon.png"></image>
				<text>待发货</text>
			</view>
		</view>
		<view @tap="toOrderFour" class="pay list">
			<view>
				<image src="/static/remao_shop/img/yifahuo_icon.png"></image>
				<text>待收货</text>
			</view>
		</view>
		<view @tap="toOrderFive" class="pay list">
			<view>
				<image src="/static/remao_shop/img/daipingjia_icon.png"></image>
				<text>待评价</text>
			</view>
		</view>
		<view @tap="toOrderSix" class="pay list">
			<view>
				<image src="/static/remao_shop/img/tuikuan.png"></image>
				<text>已完成</text>
			</view>
		</view>
	</view>
</view>
<view style="background: white;" class="main">
	<navigator class="block" url="../../packageC/ruzhu/ruzhu" v-if="hiddenShop != 1">
		<!-- <view class='order group'>
	    <view class='order-icon fl'>
	      <image src='../../img/jfzr.png'></image>
	    </view>
	    <text>商户入驻</text>
	    <image src='../../img/arrow_icon.png'></image>
	  </view> -->
		<image src="/static/remao_shop/img/user/1.png"></image>
		<text>商户入驻</text>
	</navigator>
	<navigator class="block" url="../../packageC/mineShop/mineShop" v-if="hiddenShop != 1">
		<!-- <view class='order group'>
	    <view class='order-icon fl'>
	      <image src='../../img/openShop.png'></image>
	    </view>
	    <text>我的店铺</text>
	    <image src='../../img/arrow_icon.png'></image>
	  </view> -->
		<image src="/static/remao_shop/img/user/2.png"></image>
		<text>我的店铺</text>
	</navigator>
	<navigator class="block" url="../../packageB/integralNumber/number">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-integral_icon.png'></image>
      </view>
      <text>我的积分</text>
      <text class='integList'>{{integList}}</text>
    </view> -->
		<image src="/static/remao_shop/img/user/3.png"></image>
		<text>我的积分</text>
	</navigator>
	<navigator class="block" url="../../packageB/integralshop/integralshop">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-money_icon.png'></image>
      </view>
      <text>我的礼金</text>
      <text class='integList'>{{virtual_currency}}</text>
    </view> -->
		<image src="/static/remao_shop/img/user/4.png"></image>
		<text>我的礼金</text>
	</navigator>
	<!-- <navigator url='../../packageA/myMoney/myMoney'>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-money_icon.png'></image>
      </view>
      <text>我的余额</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </navigator> -->
	<navigator class="block" url="../../packageA/spellgroup/spellgroup">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-pintuan_icon.png'></image>
      </view>
      <text>我的拼团</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/5.png"></image>
		<text>我的拼团</text>
	</navigator>
	<navigator class="block" url="../../packageA/integralOrder/integralOrder">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/order.png'></image>
      </view>
      <text>积分订单</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/6.png"></image>
		<text>积分订单</text>
	</navigator>
	<navigator class="block" url="../../packageB/mycoupon/mycoupon">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-coupon_icon.png'></image>
      </view>
      <text>我的优惠劵</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/7.png"></image>
		<text>我的优惠劵</text>
	</navigator>
	<navigator class="block" url="../../packageB/collect/collect">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-shoucang_icon.png'></image>
      </view>
      <text>我的收藏</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/8.png"></image>
		<text>我的收藏</text>
	</navigator>
	<!-- <navigator url='../../packageB/openShop/openShop'>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/openShop.png'></image>
      </view>
      <text>我要开店</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </navigator> -->
	<navigator class="block" url="../../packageB/address/address">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/dress_icon.png'></image>
      </view>
      <text>收货地址</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/9.png"></image>
		<text>收货地址</text>
	</navigator>
	<navigator class="block" url="../../packageC/bargainorders/bargainorders">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/bargainorders.png'></image>
      </view>
      <text>砍价订单</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/10.png"></image>
		<text>砍价订单</text>
	</navigator>
	<!-- <navigator url='../../packageA/message/message'>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/message.png'></image>
      </view>
      <text>我的消息</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </navigator>
   <navigator url='../../packageB/footprint/footprint'>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/footprint.png'></image>
      </view>
      <text>我的足迹</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </navigator> -->
	<!-- <view bindtap='distribution'>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/distribution.png'></image>
      </view>
      <text>分销中心</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </view> -->
	<view class="block" @tap="distribution">
		<image src="/static/remao_shop/img/user/11.png"></image>
		<text>分销中心</text>
	</view>
	<navigator class="block" url="../../packageC/loans/loans">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/loans.png'></image>
      </view>
      <text>我要贷款</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/12.png"></image>
		<text>我要贷款</text>
	</navigator>
	<navigator class="block" url="../../packageC/integralTransfer/integralTransfer">
		<!-- <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/jfzr.png'></image>
      </view>
      <text>积分转让</text>
      <image src='../../img/arrow_icon.png'></image>
    </view> -->
		<image src="/static/remao_shop/img/user/13.png"></image>
		<text>积分转让</text>
	</navigator>
	<!-- <navigator>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/mine-kefu_icon.png'></image>
      </view>
      <text>联系客服</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </navigator> -->
	<!-- <navigator url='../../packageA/aboutus/aboutus'>
    <view class='order group'>
      <view class='order-icon fl'>
        <image src='../../img/about.png'></image>
      </view>
      <text>关于我们</text>
      <image src='../../img/arrow_icon.png'></image>
    </view>
  </navigator> -->
</view>
</view>
</template>

<script>
import api from "../../../api";
var app = getApp();
var iswe7 = wx.getStorageSync("iswe7");

export default {
  data() {
    return {
      userId: 0,
      name: 'userNickName',
      getList: [],
      loginModelHidden: !0,
      code: 0,
      integList: '0',
      virtual_currency: '0',
      fxList: [],
      loginCode: '',
      img: '',
      hiddenShop: 0,
      userName: "",
      userHeadImg: "",
      uid: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    this.getIsOpen();
    wx.getStorage({
      key: 'userId',
      success: res => {
        this.setData({
          userId: res.data
        });
        this.fxListFun();
        this.Integral();
        this.userInfo();
      },
      fail: () => {
        this.getuserID(); //this.we7login();
      }
    }); // console.log(this.data.userId)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {// this.onLoad()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.Integral();
    this.userInfo();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    //信息
    userInfo: function () {
      wx.getStorage({
        key: 'userName',
        success: username => {
          this.setData({
            userName: username.data
          });
        }
      });
      wx.getStorage({
        key: 'userHeadImg',
        success: userImg => {
          this.setData({
            userHeadImg: userImg.data
          });
        }
      });
    },
    getIsOpen: function () {
      app.globalData.request({
        url: api.gzSea.open,
        data: {},
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值

        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            hiddenShop: res.data
          });
          console.log(this.hiddenShop);
        }
      });
    },
    getUser: function (e) {
      console.log('1');
      var that = this;
      wx.login({
        success: login => {
          console.log(login);
          this.setData({
            loginCode: login.code
          }); //先获取用户信息

          wx.getUserInfo({
            success: info => {
              console.info(info);
              console.log(this.loginCode);
              this.setData({
                img: info.userInfo.avatarUrl,
                name: info.userInfo.nickName
              });
              console.log(this.name, this.img); //调用后台接口，获取userID

              app.globalData.request({
                url: api.default.login,
                //仅为示例，并非真实的接口地址
                method: 'POST',
                data: {
                  code: this.loginCode,
                  nickname: this.name,
                  avatarUrl: this.img // iv: res1.iv,
                  // data: res1.rawData
                },
                header: {
                  'content-type': 'application/x-www-form-urlencoded' // 默认值

                },

                success(res2) {
                  console.log(res2);
                  wx.setStorage({
                    key: 'openid',
                    data: res2.data.openid
                  });
                  wx.setStorage({
                    key: 'userId',
                    data: res2.data.id,
                    success: function (res3) {
                      console.log(res3, 'userID');
                    },
                    fail: function (res3) {},
                    complete: function (res3) {}
                  });
                  wx.setStorage({
                    key: 'userName',
                    data: res2.data.nickname
                  });
                  wx.setStorage({
                    key: 'userHeadImg',
                    data: res2.data.avatar
                  });
                  wx.getStorage({
                    key: 'userId',
                    success: res => {
                      that.setData({
                        userId: res.data
                      });
                      that.fxListFun();
                      that.Integral();
                      that.userInfo();
                    },
                    fail: () => {
                      that.getuserID(); //this.we7login();
                    }
                  });
                }

              });
            }
          });
        }
      });
    },

    // 微擎登录
    we7login(e) {
      var t = this,
          a = wx.getStorageSync("userInfo");
      a && 0 != a.memberInfo.uid && "" != a.memberInfo ? t.setData({
        userId: a.memberInfo.uid
      }) : wx.getSetting({
        success: function (e) {
          false == e.authSetting["scope.userInfo"] ? wx.showModal({
            title: "提示",
            content: "允许小程序获取您的用户信息后才可查看线索哦",
            showCancel: !1,
            success: function (e) {
              e.confirm && wx.openSetting({
                success: function (e) {
                  1 == e.authSetting["scope.userInfo"] && (t.setData({
                    loginModelHidden: !1
                  }), wx.removeStorageSync("userInfo"));
                }
              });
            }
          }) : (wx.removeStorageSync("userInfo"), t.setData({
            loginModelHidden: !1
          }));
        }
      });
    },

    // 获取用户信息
    updateUserInfo: function (e) {
      var t = this;
      app.globalData.util.getUserInfo(function (e) {
        e = wx.getStorageSync("userInfo");
        let userId = wx.getStorageSync("userId");
        var that = this;
        t.setData({
          userId: userId,
          loginModelHidden: !0
        });
        console.log(this.loginModelHidden);
        t.fxListFun();
        t.Integral();
        t.userInfo();
      }, e.detail);
    },

    getuserID() {
      // console.log('我被调用了')
      wx.getStorage({
        key: 'userId',
        success: res => {
          this.setData({
            uid: res.data
          });
          this.trolley();
        },
        fail: res => {
          console.log(res);
          wx.showToast({
            title: '请先登录',
            icon: 'none'
          }); // setTimeout(function() {
          // 	if (iswe7 == 1) {
          // 		wx.navigateTo({
          // 			url: '../../packageA/login/login'
          // 		})
          // 	} else {
          // 		wx.navigateTo({
          // 			url: '../../packageA/logins/login',
          // 		})
          // 	}
          // }, 2000)
        }
      });
    },

    // 订单路由
    toOrderOne() {
      // console.log(this.data.userId)
      if (this.userId) {
        wx.reLaunch({
          url: '../../packageB/order/order?status=0&userId=' + this.userId
        });
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        });
      }
    },

    toOrderTwo() {
      if (this.userId) {
        wx.reLaunch({
          url: '../../packageB/order/order?status=1&userId=' + this.userId
        });
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        });
      }
    },

    toOrderThree() {
      if (this.userId) {
        wx.reLaunch({
          url: '../../packageB/order/order?status=2&userId=' + this.userId
        });
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        });
      }
    },

    toOrderFour() {
      if (this.userId) {
        wx.reLaunch({
          url: '../../packageB/order/order?status=3&userId=' + this.userId
        });
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        });
      }
    },

    toOrderFive() {
      if (this.userId) {
        wx.reLaunch({
          url: '../../packageB/order/order?status=4&userId=' + this.userId
        });
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        });
      }
    },

    toOrderSix() {
      if (this.userId) {
        wx.reLaunch({
          url: '../../packageB/order/order?status=5&userId=' + this.userId
        });
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none'
        });
      }
    },

    //获取用户信息（积分）
    Integral: function () {
      // console.log(this.data.userId)
      app.globalData.request({
        url: api.default.user_info,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.userId
        },
        method: 'POST',
        success: res => {
          // console.log(res)
          this.setData({
            integList: res.user_info.integral,
            virtual_currency: res.user_info.virtual_currency
          });
        }
      });
    },
    //判断是否是分销商，跳转相应页面
    fxListFun: function () {
      app.globalData.request({
        url: api.default.distribution_sales,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.userId
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            fxList: res
          });
        }
      });
    },
    distribution: function () {
      if (this.fxList.status != 1) {
        wx.showToast({
          title: this.fxList.msg,
          icon: 'none'
        });
        setTimeout(function () {
          wx.navigateTo({
            url: '../../packageB/distribution/distribution'
          });
        }, 1000);
      } else {
        wx.navigateTo({
          url: '../../packageB/DistributionCenter/DistributionCenter?kong=' + !1
        });
      }
    },

    totemp() {
      wx.navigateTo({
        url: '../../packageB/testTemplate/testTemplate'
      });
    }

  }
};
</script>
<style>
@import "./mine.css";
</style>